package com.frxuexi.park2209.repair

import com.frxuexi.base.mvvm.BaseViewModel
import com.frxuexi.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import javax.inject.Inject

@HiltViewModel
class RepairViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {

    val allRepairs = MutableStateFlow<String>("")
    val myRepairs = MutableStateFlow<String>("")
    val addRepair = MutableStateFlow<String>("")
    val appointRepair = MutableStateFlow<String>("")

    fun getAllRepairs(){
        httpRequest({apiService.getAllRepairs()},{allRepairs.value=it})
    }

    fun getMyRepairs(map: Map<String,Int>){
        httpRequest({apiService.getMyRepairs(mapToBody(map))},{myRepairs.value=it})
    }

    fun addRepair(map: Map<String,Any>){
        httpRequest({apiService.addRepair(mapToBody(map))},{addRepair.value=it})
    }

    fun appointRepair(map: Map<String, Any>){
        httpRequest({apiService.appointRepair(mapToBody(map))},{appointRepair.value=it+map.get("repairId")})
    }
}